package com.ljs.threadpooldemo.controller;

import com.ljs.threadpooldemo.entity.request.ThreadRequest;
import com.ljs.threadpooldemo.service.TestAsynService;
import com.ljs.threadpooldemo.service.run.RunnableA;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

@RestController
public class TestThredPoolController {
    @Resource
    ExecutorService getExecutorService;
    @Resource
    TestAsynService testAsynService;
    @GetMapping("/testExecutorService")
    public boolean test() throws ExecutionException, InterruptedException {
        boolean bln=false;
        RunnableA runnableA=new RunnableA();
        Future future=  getExecutorService.submit(runnableA);
        if(future.get()==null){
            bln=true;
        }

        return  bln;
    }
    @GetMapping("/testAsyn")
    public void testAsyn(ThreadRequest threadRequest){
        System.out.println("我准备调用异步方法"+Thread.currentThread().getName());
        testAsynService.testAsyn();
    }
}
